package com.itheima.dao;

import com.itheima.domain.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author robin
 * @version 1.0
 */
public interface UserDao {
    //@TODO 1.动态name条件完成查询用户
    @Select("<script>select * from user <where> <if test=\"name!=null and name!=''\"> name=#{name} </if>  </where> </script>")
    public List<User> selectPage(String name);

    //@TODO 2.根据主键查询用户
    @Select("select * from user where id=#{id}")
    public User select(Long id);

    //@TODO 3.增加一个用户
    @Insert("insert into user values(null,#{name},#{age},#{address})")
    public void insert(User user);

    //@TODO 4.根据主键删除一个用户
    @Delete("delete from user where id=#{id}")
    public void delete(Long id);

    //@TODO 5.修改一个用户
    @Update("update user set name=#{name},age=#{age},address=#{address} where id=#{id}")
    public void update(User user);
}
